var foods = function() {
	this.alive = [];
	this.x = [];
	this.y = [];
	this.l = [];
	this.speed = [];
	this.orange = new Image();
	this.blue = new Image();
	this.pic = [this.orange, this.blue];
}
foods.prototype.num = 30; //foods-数量
foods.prototype.init = function() {
	for (var i = 0; i < this.num; i++) {
		this.alive[i] = false;
		this.x[i] = 0;
		this.y[i] = 0;
		this.l[i] = 0;
		this.speed[i] = Math.random() * 0.04 + 0.005; //[0.05,0.015]
		this.born(i);
	}
	this.orange.src = './img/fruit.png';
	this.blue.src = './img/blue.png';
}

foods.prototype.draw = function() {
	for (var i = 0; i < this.num; i++) {
		//find ane grow fly
		if (this.alive[i]) {
			if (this.l[i] <= 14) {
				this.l[i] += this.speed[i] * DELTIME;
			} else {
				this.y[i] -= this.speed[i] * (Math.pow(1, Math.floor(Math.random() * 1000)) * 4) * DELTIME;
			}
			if (i % 2 == 0) {
				ctx2.drawImage(this.pic[0], this.x[i] - this.l[i] * 0.5, this.y[i] - this.l[i] * 0.5, this.l[i], this.l[i]);
			} else {
				ctx2.drawImage(this.pic[1], this.x[i] - this.l[i] * 0.5, this.y[i] - this.l[i] * 0.5, this.l[i], this.l[i]);
			}
			if (this.y[i] < 30) {
				this.alive[i] = false; //foods
			}
		}
	}
}
foods.prototype.born = function(i) {
	var aneId = Math.floor(Math.random() * ane.num);
	this.x[i] = ane.x[aneId]; //foods-X坐标
	this.y[i] = canHeight - ane.y[aneId]; //foods-Y坐标
	this.l[i] = 0;
	this.alive[i] = true;
}

function foodsLimited() { //判断食物数量	
	var num = 0;
	for (var i = 0; i < foods.num; i++) {
		if (foods.alive[i]) {
			num++;
		}
		if (num < 15) {
			// create food
			createFoods();
			return;
		}
	}
}

function createFoods() {
	for (var i = 0; i < foods.num; i++) {
		if (!foods.alive[i]) {
			foods.born(i);
			return;
		}
	}
}